home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ecstr3.arc / MEMREV.C < prev    next >
C/C++ Source or Header  |  1987-03-04  |  894b  |  35 lines

  1. /*  File   : memrev.c
  2.     Author : Richard A. O'Keefe.
  3.     Updated: 1 June 1984
  4.     Defines: memrev()
  5.  
  6.     memrev(dst, src, len)
  7.     moves len bytes from src to dst, in REVERSE order.  NUL characters
  8.     receive no special treatment, they are moved like the rest.  It is
  9.     to strrev as memcpy is to strcpy.
  10.  
  11.     Note: this function is perfectly happy to reverse a block into the
  12.     same place, memrev(x, x, L) will work.
  13.     It will not work for partially overlapping source and destination.
  14. */
  15.  
  16. #include "strings.h"
  17.  
  18. void memrev(dsta, srca, len)
  19.     register char *dsta, *srca;
  20.     int len;
  21.     {
  22.        register char *dstz, *srcz;
  23.        register int t;
  24.  
  25.        if (len <= 0) return;
  26.        srcz = srca+len;
  27.        dstz = dsta+len;
  28.        while (srcz > srca) {
  29.            t = *--srcz;
  30.            *--dstz = *srca++;
  31.            *dsta++ = t;
  32.        }
  33.     }
  34.  
  35.